// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
const { ipcRenderer, shell } = require('electron') // Com.01 进程间通信


window.addEventListener('DOMContentLoaded', () => {
  for (const versionType of ['chrome', 'electron', 'node']) {
    document.getElementById(`${versionType}-version`).innerText = process.versions[versionType]
  }

  // Skill.02.Com.02 >>> 进程间通信 start
  // Com.02 进程间通信
  // Com.02.1 发送消息
  ipcRenderer.send('message', 'hello from renderer')
  // Com.02.2 监听消息回复
  ipcRenderer.on('reply', (event, arg) => {
    // document.getElementById('message').innerHTML = arg
    console.log('ipcRenderer receive msg:', arg)
    // event.sender.send('message', 'reply receive')
  })
  // .02.Com.02 进程间通信 end





// Skill.04 >>>  系统通知 start
  let myNotification = new Notification('打开系统通知', {
    title: '打开系统通知',
    body: '通知正文内容2',
    icon: 'images/app.ico',
    silent: false, //在显示通知时是否发出系统提示音
    // timeoutType: 'never'
  })

  myNotification.onclick = (event) => {
    // event.preventDefault();
    console.log('点击通知')
    // 默认浏览器打开
    shell.openExternal('https://www.baidu.com')
  }
// .04 系统通知 end

})

